// utils/component/sliderMenu/sliderMenu.js
const util = require('../../util.js')
Component({
  options: {
    multipleSlots: true // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */
  properties: {
    activeIndex: {
      type: Number,
      value: 0
    },
    tabs: {
      type: [],
      value: [""],
      observer: function(newValue, oldValue) {
        var width = wx.getSystemInfoSync().windowWidth
        var count = newValue.length > 0 ? newValue.length : 1
        var sliderWidth = width / count - 0.5
        this.setData({ sliderWidth: sliderWidth})
      }
    }, 
    fixed: {
      type: Number,
      value: 0  // 0 fixed 固定  1 // relative 跟随
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    sliderWidth: 0,
    sliderLeft: 0,
    screenWidth: wx.getSystemInfoSync().windowWidth*2,
  },

  ready: function() {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    tabClick: function (e) {
      this.setData({
        activeIndex: e.currentTarget.id
      });
      this.triggerEvent("tabChange", e.currentTarget.id)
    },
    upper: function(e) {
      // this.triggerEvent("upper", this.properties.activeIndex)
    },
    lower: function(e) {
      this.triggerEvent("lower", this.data.activeIndex)
    },
  }
})
